﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling;
using Microsoft.Practices.EnterpriseLibrary.Logging;
using Shop.Core.Configuration;
using Shop.Intermediate;
using DoNet.Common.Utilities;

namespace Shop.WebApp
{
    public class BasePage : System.Web.UI.Page
    {
        public const string  ERROR_PAGE = "Error.aspx";
        
        public void ProcessUnhandledException(Exception ex)
        {
            try
            {
                bool result = ExceptionPolicy.HandleException(ex, "Global Policy");
                if (result)
                {
                    string message = "发生未知错误，请联系管理员！";
                    MessageBox.Show(this.Page, message);
                    return;
                }
            }
            catch
            {
                string message = "发生了一个不知道的异常，请检查日志文件查看详细信息。";
                LogEntry log = new LogEntry();
                log.Priority = Log.Priority.High;
                log.Message = message;
                Logger.Write(log);
                MessageBox.Show(this.Page, message, ERROR_PAGE);
            }
        }
    }

    public struct Log
    {
        public struct Priority  
        {
            public const int Lowest  = 0;
            public const int Low     = 1;
            public const int Normal  = 2;
            public const int High    = 3;
            public const int Highest = 4;
        };

        public struct Category
        {
            public const string General = "General";
            public const string Trace = "Trace";
        };
    }
}
